import { request } from './axios.js'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const service = {
  get(url, params) {
    const config = {
      method: 'get',
      url: url
    }
    if (params) {
      config.params = params;
    }
    return request(config)
  },
  async post(url, data) {
    const config = {
      method: 'post',
      url: url
    }
    if (data) {
      config.data = data;
    }
    try {
      NProgress.start()
      let res = null
      if (config) {
        res = await request(config)
        NProgress.done()
      }
      return new Promise((resolve) => {
        resolve(res);
      })
    } catch (err) {
      window.console.log(err)
    }
  }
}
export default service